package com.zcb.agrimarket.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zcb.agrimarket.mapper.ArrangeMapper;
import com.zcb.agrimarket.mapper.LabMapper;
import com.zcb.agrimarket.pojo.Arrange;
import com.zcb.agrimarket.pojo.StudentApplyLog;
import com.zcb.agrimarket.service.StudentApplyLogService;
import com.zcb.agrimarket.mapper.StudentApplyLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
* @author KarrySmile
* @description 针对表【student_apply_log(学生申请表)】的数据库操作Service实现
* @createDate 2024-04-05 22:52:26
*/
@Service
public class StudentApplyLogServiceImpl extends ServiceImpl<StudentApplyLogMapper, StudentApplyLog>
    implements StudentApplyLogService{

    @Autowired
    LabMapper labMapper;

    @Autowired
    ArrangeMapper arrangeMapper;

    public ArrayList<StudentApplyLog> selectList(Integer page, Integer pageSize, Long semesterId, Integer week, Integer day, Integer session, Long labType){
        ArrayList<Long> labIdList = labMapper.selectByLabtype(labType);
        ArrayList<StudentApplyLog> studentApplyLogArrayList = new ArrayList<>();
        for(long id:labIdList){
            Arrange arrange = arrangeMapper.selectByMe(id,semesterId,week,day,session);
            //如果该实验室从未有人借用或者之前借用记录被驳回则可以进行再次借用
            if(arrange==null||arrange.getStatus()==0){
                StudentApplyLog studentApplyLog = new StudentApplyLog();
                studentApplyLog.setLabId(id);
                studentApplyLog.setSemesterId(semesterId);
                studentApplyLog.setWeek(week);
                studentApplyLog.setDay(day);
                studentApplyLog.setSession(session);
                studentApplyLogArrayList.add(studentApplyLog);
            }
        }
        return studentApplyLogArrayList;
    }

    @Autowired
    StudentApplyLogMapper studentApplyLogMapper;

    @Override
    public void update(StudentApplyLog studentApplyLog) {
        studentApplyLogMapper.update(studentApplyLog);
    }

}




